package ahpu.piconet.util;

import java.text.DecimalFormat;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;

import ahpu.piconet.service.DataService;

public class DataThread implements Runnable {

	@Autowired
	private DataService dataService;

	@Override
	public void run() {
		addData();
	}

	public void addData() {
		DecimalFormat dcmFmt = new DecimalFormat("0.00");
		Random rand = new Random();
		float electricity = rand.nextFloat() * 20;
		float voltage = rand.nextFloat() * 220;
		dataService.saveData(Float.parseFloat(dcmFmt.format(electricity)),
				Float.parseFloat(dcmFmt.format(voltage)));
	}

}
